{% extends 'template.html' %}
{% load staticfiles %}

{% block username %}
    {{ request.user.username }}
{% endblock %}

{% block content %}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Celery Worker 状态</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="btn-group">
                            <a>
                                <button type="button" class="btn btn-success" onclick="sync_running_worker()">
                                    手动同步worker状态
                                </button>
                            </a>
                            <a>
                                <button id='bt-del' data-text="确定取消监控worker? 0个" type="button"
                                        class="btn btn-danger">删除
                                </button>
                            </a>
                            <a>
                                <button id='bt-receive-user' type="button" class="btn btn-info">接收告警人员
                                </button>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">
                        {% if all_workers %}
                            <table id="mytable" width="100%" cellspacing="0"
                                   class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th class="center sorting_disabled">
                                        <label class="pos-rel">
                                            <input id='chb-all' type="checkbox"/>
                                        </label>
                                    </th>
                                    <th style="display: none;">id</th>
                                    <th>celery名称</th>
                                    <th>执行次数</th>
                                    <th>状态</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for worker in all_workers %}
                                    <tr>
                                        <td class=" dt-body-center"><input type="checkbox"></td>
                                        <td style="display: none;" id="{{ worker.id }}"
                                            value="{{ worker.id }}"
                                            name="{{ worker.id }}">{{ worker.id }}</td>
                                        <td>{{ worker.celery_hostname }}</td>
                                        <td>{{ worker.total }}</td>
                                        <td>
                                            {% if worker.status == 1 %}
                                                <button type="button" class="btn btn-success btn-circle"><i
                                                        class="fa fa-check"></i>
                                                </button>
                                            {% else %}
                                                <button type="button" class="btn btn-danger btn-circle"><i
                                                        class="fa fa-times"></i>
                                                </button>
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p>还没有监控的worker，请先同步！</p>
                        {% endif %}
                    </div>
                </div>
            </div>

            <div id="is_superuser" data-is-superuser="{{ is_superuser }}"></div>

        </div>
    </div>

    <div class="modal fade" id="myModalReceiveNotice" role="dialog" aria-labelledby="myModalLabelReceiveNotice"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabelReceiveNotice"></h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">接收告警人(可选)</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="receive_user" style="width: 100%" multiple="multiple">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer" id="modal-footer">
                    <button id='bt-save' type="button" class="btn btn-primary">保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>

{% endblock %}
{% block bodyjs %}
    <script src="/static/js/select2.min.js"></script>
    <script src="/static/js/jquery.dataTables.min.js"></script>
    <script src="/static/js/dataTables.colVis.js"></script>
    <script src="/static/js/celery_worker_status.js?v=sdf9htnjf123ddfadsang0sf"></script>
    <!-- showloading.js-->
    <script src="/static/js/showloading.min.js"></script>
{% endblock %}
{% block css %}
    <link href="/static/css/jquery.dataTables.css" rel="stylesheet" type="text/css">
    <link href="/static/css/dataTables.colVis.css" rel="stylesheet" type="text/css">
    <!-- showloading.css-->
    <link href="/static/css/showloading.css" rel="stylesheet" media="screen">
{% endblock %}
